<template>
  <div class="addMonthCard-box">
    <!-- 导航栏 -->
    <div class="addMonthCard">
      <div class="addMonthCardCenter">
        <el-page-header @back="goBack">
          <template v-slot:content>
            <!-- 在这里定义您想要显示的内容 -->
            <span>添加企业</span>
          </template>
        </el-page-header>
      </div>
      <div class="addMonthCardCenter1">黑马程序员</div>
    </div>
    <div v-if="showWord" class="addMonthCard-box">
      <div class="addMonthCard-box-1">
        <div style="height: 300px; margin:30px 30px ">
          <el-steps direction="vertical" :active="1">
            <el-step title="角色信息" />
            <el-step title="权限信息" />
            <el-step title="检查并完成" />
          </el-steps>
        </div>
        <div class="addMonthCard-box-1-2">
          <el-card class="box-card" style="width: 40vw;">
            <div>角色信息</div>
            <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
              <el-form-item label="角色名称" prop="roleName">
                <el-input v-model="ruleForm.roleName" />
              </el-form-item>
              <el-form-item label="角色描述" prop="remark">
                <el-input v-model="ruleForm.remark" type="textarea" />
              </el-form-item>
            </el-form>
          </el-card>
        </div>
      </div>
    </div>
    <div v-if="showWord1" class="addMonthCard-box">
      <div class="addMonthCard-box-1">
        <div style="height: 300px; margin:30px 30px ">
          <el-steps direction="vertical" :active="2">
            <el-step title="角色信息" />
            <el-step title="权限信息" />
            <el-step title="检查并完成" />
          </el-steps>
        </div>
        <div class="addMonthCard-box-1-2">
          <div>
            <el-card class="box-card">
              <div class="clearfix">
                <h4>权限配置</h4>
                <div style="display:flex;flex-flow:row wrap">
                  <div v-for="item in permissionData" :key="item.id" style="width:30%;border:1px solid #f5f7fa">
                    <div style="background-color:#f5f7fa;width:100px;line-height:30px;text-align:center">{{ item.title }}</div>
                    <el-tree
                      ref="permTree"
                      :data="item.children"
                      :props="{ label: 'title' }"
                      show-checkbox
                      default-expand-all
                      node-key="id"
                    />
                  </div>
                </div>
              </div>
            </el-card>
          </div>
        </div>
      </div>
    </div>
    <div class="submit-xia">
      <div class="submit-xia1">
        <el-button v-if="showSubmit" @click="ShangSubmit">上一步</el-button>
        <el-button type="primary" @click="XiaSubmit">下一步</el-button>
      </div>
    </div>
    <div>
      <div v-if="showWord3" class="addMonthCard-box">
        <div class="addMonthCard-box-1">
          <div style="height: 300px; margin:30px 30px ">
            <el-steps direction="vertical" :active="3">
              <el-step title="角色信息" />
              <el-step title="权限信息" />
              <el-step title="检查并完成" />
            </el-steps>
          </div>
          <div class="addMonthCard-box-1-2">
            <div>
              <el-card class="box-card">
                <div class="clearfix">
                  <h4>权限配置</h4>
                  <div style="display:flex;flex-flow:row wrap">
                    <div v-for="item in permissionData" :key="item.id" style="width:30%;border:1px solid #f5f7fa">
                      <div style="background-color:#f5f7fa;width:100px;line-height:30px;text-align:center">{{ item.title }}</div>
                      <el-tree
                        ref="permTree"
                        :data="item.children"
                        :props="{ label: 'title' }"
                        show-checkbox
                        default-expand-all
                        node-key="id"
                      />
                    </div>
                  </div>
                </div>
              </el-card>
            </div>
          </div>
        </div>
      </div>
      <div class="submit-xia">
        <div class="submit-xia1">
          <el-button v-if="showSubmit" @click="ShangSubmit">上一步</el-button>
          <el-button type="primary" @click="XiaSubmit">下一步</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getParkSysPermisionAllTree } from '@/api/systeManagement/role'
// import { postParkSysRole } from '@/api/systeManagement/role'
export default {
  data() {
    return {
      ruleForm: {
        roleName: '',
        remark: '',
        perms: ''
      },
      rules: {
        roleName: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      },
      data: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        children: [{
          id: 5,
          label: '二级 2-1'
        }, {
          id: 6,
          label: '二级 2-2'
        }]
      }, {
        id: 3,
        label: '一级 3',
        children: [{
          id: 7,
          label: '二级 3-1'
        }, {
          id: 8,
          label: '二级 3-2'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      showWord: true,
      showWord1: false,
      showSubmit: false,
      showWord3: false,
      permissionData: [] // 权限名称
    }
  },
  methods: {
    // 跳转页面
    goBack() {
      this.$router.push('/role')
    },
    // 上一步
    ShangSubmit() {
      this.showWord = true
      this.showWord1 = false
      this.showSubmit = false
    },
    // 下一步
    async XiaSubmit() {
      this.$refs.ruleForm.validate()
      if (this.ruleForm.roleName || this.ruleForm.remark) {
        this.showWord = false
        this.showWord1 = true
        this.showSubmit = true
      }
      const res = await getParkSysPermisionAllTree()
      console.log(res)
      this.permissionData = res.data
      // const res = await postParkSysRole(this.ruleForm)
      // console.log(res)
      // this.$message.success('操作成功')
    }
  }
}
</script>
<style scoped>
.addMonthCard-box{
  height: 700px;
  background-color: #f4f6f8;
}
.addMonthCard-box-1{
  display: flex;
}
.addMonthCard-box-1-2{
  margin: 30px auto;
}
.addMonthCard{
 width: 100%;
 height: 60px;
 background-color: #fff;
 display: flex;
flex-direction:row;
justify-content:space-between;
 font-size: 18px;
}
.addMonthCardCenter1{
width: 100px;
height: 70px;
margin-top: 20px;
margin-right: 20px;
}
.addMonthCardCenter{
  width: 200px;
  height: 70px;
 margin-top: 20px;
 margin-left: 20px;
}
.submit{
  display: block;
  /* width: 150px; */
  margin: 40px auto;

}
.demo-ruleForm{
   margin-top: 30px;
}
.submit-xia1{
  display: flex;
  margin: 30px auto;
   margin-left: 45vw;
}

</style>
